#include<iostream>
#include<string>
#include<unordered_map>
using namespace std;
class Solution {
public:
    bool checkAlmostEquivalent(string word1, string word2) {
        unordered_map<int, int> p;
        for (const auto& ch : word1)
            p[ch - 'a']++;
        for (const auto& ch : word2)
            p[ch - 'a']--;
        for (const auto& tmp : p)
        {
            if (tmp.second >= 4 || tmp.second <= -4)
                return false;
        }
        return true;
    }
};
int main()
{
    string word1 = "abcdeef";
    string word2 = "abaaacc";
    cout << Solution().checkAlmostEquivalent(word1, word2) << endl;
    return 0;
}